<?php
Globals::requireClass('Controller');
Globals::requireTable('Order');
Globals::requireTable('Custom');
Globals::requireTable('Custom_contact');
Globals::requireTable('Custom_site');
Globals::requireTable('Custom_site_contact');

class AjaxController extends Controller
{
	protected $OrderTable;
	protected $CustomTable;
	protected $CustomContactTable;
	protected $CustomSiteTable;
	protected $CustomSiteContactTable;
	
	public static $defaultConfig = array(
		'viewEnabled'	=> true,
		'layoutEnabled'	=> true,
		'title'			=> null
	);
	
	public function __construct($config = null)
	{
		parent::__construct($config);
		$this->OrderTable = new OrderTable($config);
		$this->CustomTable = new CustomTable($config);
		$this->CustomContactTable = new Custom_contactTable($config);
		$this->CustomSiteTable = new Custom_siteTable($config);
		$this->CustomSiteContactTable = new Custom_site_contactTable($config);
	}
	
	public function indexAction(){
        
	}
        
        public function lading_codeAction(){
            $lading_code = $this->getParam('lading_code');
            
            $url = "http://test.fob001.cn/api/shport/api20170413ypcd.php?key=900150983cd24fb0d6963g7d28e17f11&bl={$lading_code}";
	    $re = file_get_contents($url);
	    echo $re;
            
            exit();
        }
    
	public function custominfoAction(){
	    $id = $this->getIntParam('id');
	    $contact = $this->CustomContactTable->listAll(array('status'=>1,'custom_id'=>$id));
	    
	    $site = $this->CustomSiteTable->listAll(array('status'=>1,'custom_id'=>$id));
	    
	    echo json_encode(array('contact'=>$contact,'site'=>$site));
	    exit();
	}
	
	public function customsiteinfoAction(){
	    $id = $this->getIntParam('id');
	    $contact = $this->CustomSiteContactTable->listAll(array('status'=>1,'custom_id'=>$id));
	    echo json_encode($contact);
	    exit();
	}
	
	public function shipnameAction(){
	    $name = $this->getParam('name');
	    $name = str_replace(' ', '%20', $name);
	    $url = "http://test.fob001.cn/api/shport/api20170413temp.php?key=900150983cd24fb0d6963g7d28e17f11&vesselname={$name}";
	    $re = file_get_contents($url);
	    echo $re;
	    exit();
	}
	
	protected function out()
	{
		$this->layout->nav		= 'index';
		parent::out();
	}
}

Config::extend('AjaxController', 'Controller');

